package com.example.robertluozizhao.framecollectdemo.adapter;

import android.annotation.SuppressLint;
import androidx.recyclerview.widget.RecyclerView;
import android.view.ViewGroup;

import com.example.robertluozizhao.framecollectdemo.R;
import com.example.robertluozizhao.framecollectdemo.adapter.base.BaseReycleAdapter;
import com.example.robertluozizhao.framecollectdemo.adapter.holder.ItemRcViewHolder01;
import com.example.robertluozizhao.framecollectdemo.adapter.holder.ItemRcViewHolder02;
import com.example.robertluozizhao.framecollectdemo.common.Constants;
import com.example.robertluozizhao.framecollectdemo.data.test.TestRcycleitemBean;

import java.util.List;
/**
 * Created by robert.luozizhao on 2018/2/2.
 */

public class PageItemRvAdapter extends BaseReycleAdapter{

    public PageItemRvAdapter(List<TestRcycleitemBean> data) {
        super(data);
        setHasStableIds(true);
    }

    //1 bind layout
    @SuppressLint("ResourceType")
    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        if (viewType == Constants.ITEM_TYPE_ONE) {
            return new ItemRcViewHolder01(R.layout.item_rc_test01, parent);
        } else {
            return new ItemRcViewHolder02(R.layout.item_rc_test02, parent);
        }
    }

    //2 set data
    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        TestRcycleitemBean bean = (TestRcycleitemBean) sData.get(position);
        switch (bean.getType()) {
            case Constants.ITEM_TYPE_ONE:
                ItemRcViewHolder01 holder1 = (ItemRcViewHolder01) holder;
                holder1.setData(bean);
                break;
            case Constants.ITEM_TYPE_TWO:
                ItemRcViewHolder02 holder2 = (ItemRcViewHolder02) holder;
                holder2.setData(bean);
                break;
        }
    }


    protected int setCustomItemType(int position) {
        TestRcycleitemBean bean = (TestRcycleitemBean) sData.get(position);
        if (sData != null) {
            return bean.getType();
        }
        return super.getItemViewType(position);
    }


    @Override
    public int getItemCount() {
        return sData.size();
    }

/*    @Override
    public RecyclerView.ViewHolder onCreateHeaderViewHolder(ViewGroup parent) {
       return new NormalTextHolder(R.layout.item_sticky_head,parent);
    }

    @Override
    public void onBindHeaderViewHolder(RecyclerView.ViewHolder holder, int position) {
        NormalTextHolder stickyHeadHolder = (NormalTextHolder) holder;
        stickyHeadHolder.textView.setText(String.valueOf(position));
    }*/
}
